<?php

	if($_POST)
	{
		if(!trim($_POST['faceimg'])&&$_FILES['photo']['name'])
		{
			$upimg = $_->images->upLoad('photo',array('width'=>520,'height'=>250));
			$_POST['faceimg'] = 'http://pic.dev'.substr($upimg,12);
		}
		$data = array(
			'title' => $_POST['title'],
			'description' => $_POST['descrption'],
			'cates' => $_POST['cates'],
			'catename' => $_POST['sele-text'],
			'faceimg' => $_POST['faceimg'],
			'content' => $_POST['content'],
			'tage' => $_POST['tage']?implode(',',$_POST['tage']):'',
			'author'=>$_POST['author']?$_POST['author']:'37.5°',
			'addtime' =>$_POST['playdate'] ? strtotime($_POST['playdate']):time(),
		);
		if(!$_POST['title'] || !$_POST['cates'] )
		{
			header('location:?res=2');exit;
		}
		if($_POST['id'])
		{
			if($_->product->_update($data,array('id'=>$_POST['id'])))
			{
				header('location:/admins/manage_product.php');
			}exit;
		}elseif($_->product->_insert($data))
		{
			header('location:?res=1');exit;
		}
	}
	if($id=intval($_GET['id']))
	{
		$product = $_->product->_select('',array('id'=>$id));
		$product = $product[0];		
	}
	$product['tage'] = explode(',',$product['tage']);
	$catename = $_->cates->_select(array('id as cates','catename'),array('type'=>2,'status'=>1));
	$notice = intval($_GET['res']);
	$tages = array('php'=>'php','js'=>'js','css'=>'css','other'=>'其他');
	$smarty->_assign(array('notice','catename','product','tages'));
	$smarty->_display();
?>